package com.dotstone.chipism.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dotstone.chipism.util.ConvertUtil;
import com.dotstone.chipism.util.DeviceManager;
import android.util.Log;

public class Scene {

	private String sceneId;
	private String userId;
	private String sceneName="";
	private long createTime;
	private int status;
	private int position;
	private int bsId;
	private String hid;
	private boolean isSelect = false;
	private boolean select;
	private float Angle1;
	private float Angle2;
	private List<Scene_Task> scene_Tasks = new ArrayList<Scene_Task>();
	private List<Device> openDevices = new ArrayList<Device>();
	private List<Device> closeDevices = new ArrayList<Device>();
	private List<Device> devices = new ArrayList<Device>();
	private List<String> openmids = new ArrayList<String>();
	private List<String> closemids = new ArrayList<String>();
	private HashMap<String, List<Device>> deviceMap = new HashMap<String, List<Device>>();
	private List<Cmd_Open> open_cmds = new ArrayList<Cmd_Open>();
	private List<Cmd_Close> close_cmds = new ArrayList<Cmd_Close>();
	private List<Device> close_ir_devices = new ArrayList<Device>();
	private List<Device> open_ir_devices = new ArrayList<Device>();

	public List<Scene_Task> getScene_Tasks() {
		return scene_Tasks;
	}

	public void setScene_Tasks(List<Scene_Task> scene_Tasks) {
		this.scene_Tasks = scene_Tasks;
		Log.i("wmy", "scene_Tasks.size() = " + scene_Tasks.size());
		open_cmds.clear();

		// getCmd();
		getDeviceList();
		getMid();
		getDeviceMap();
		getOpenCmd();
		getCloseCmd();
		getIrCmd();
		Log.e("wmy", "共有" + open_cmds.size());
	}

	public void clearTask() {
		scene_Tasks.clear();
		open_cmds.clear();
		devices.clear();
		openmids.clear();
		closemids.clear();
		openDevices.clear();
		closeDevices.clear();
		close_cmds.clear();
		close_ir_devices.clear();
		open_ir_devices.clear();
	}

	public int getBsId() {
		return bsId;
	}

	public void setBsId(int bsId) {
		this.bsId = bsId;
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public float getAngle1() {
		return Angle1;
	}

	public void setAngle1(float angle1) {
		Angle1 = angle1;
	}

	public float getAngle2() {
		return Angle2;
	}

	public void setAngle2(float angle2) {
		Angle2 = angle2;
	}

	public boolean isSelect() {
		return isSelect;
	}

	public void setSelect(boolean isSelect) {
		this.isSelect = isSelect;
	}

	public String getSceneId() {
		return sceneId;
	}

	public void setSceneId(String sceneId) {
		this.sceneId = sceneId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getSceneName() {
		return sceneName;
	}

	public void setSceneName(String sceneName) {
		this.sceneName = sceneName;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getHid() {
		return hid;
	}

	public void setHid(String hid) {
		this.hid = hid;
	}

	public List<Device> getDevices() {
		return devices;
	}

	public void setDevices(List<Device> devices) {
		this.devices = devices;
		// getMid();
		// getDeviceMap();
		// getOpenCmd();
		// getCloseCmd();
	}

	public Scene() {
		super();

	}

	public Scene(String sceneId, String userId, String sceneName, int status, String hid) {
		super();
		this.sceneId = sceneId;
		this.userId = userId;
		this.sceneName = sceneName;
		this.status = status;
		this.hid = hid;
	}

	private void getDeviceList() {
		Map<String,String> switchtypeMap=new HashMap<String,String>();
		for (int i = 0; i < scene_Tasks.size(); i++) {
			if (scene_Tasks.get(i).getCmdName().split("\\|")[0].equals("开")) {
			//	Device device = DeviceManager.getInstance().getDeviceByName(scene_Tasks.get(i).getCmdName().split(";")[1]);
				Device device = DeviceManager.getInstance().getDeviceById(scene_Tasks.get(i).getDeviceId());
				/*if(scene_Tasks.get(i).getCmdName().split("\\|")[1].contains("(1键)")){
					device.setSwitchName(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				}else if(scene_Tasks.get(i).getCmdName().split("\\|")[1].contains("(2键)")){
					device.setSwitchName2(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				}else if(scene_Tasks.get(i).getCmdName().split("\\|")[1].contains("(3键)")){
					device.setSwitchName3(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				}*/
				device.setSwitchName(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				openDevices.add(device);
				Log.i("wmy", "任务为开的设备：" + device.getSwitchName());
				Log.i("wmy", "xxx：" );
			} else if (scene_Tasks.get(i).getCmdName().split("\\|")[0].equals("关")) {
				//Device device = DeviceManager.getInstance().getDeviceByName(scene_Tasks.get(i).getCmdName().split(";")[1]);
				Device device = DeviceManager.getInstance().getDeviceById(scene_Tasks.get(i).getDeviceId());
				/*if(scene_Tasks.get(i).getCmdName().split("\\|")[1].contains("(1键)")){
					device.setSwitchName(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				}else if(scene_Tasks.get(i).getCmdName().split("\\|")[1].contains("(2键)")){
					device.setSwitchName2(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				}else if(scene_Tasks.get(i).getCmdName().split("\\|")[1].contains("(3键)")){
					device.setSwitchName3(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				}*/
				device.setSwitchName(scene_Tasks.get(i).getCmdName().split("\\|")[1]);
				closeDevices.add(device);
				Log.i("wmy", "任务为关的设备：" + device.getSwitchName() + " closeDevices.size() = " + closeDevices.size());
			}

		}

	}

	private void getMid() {
		for (int i = 0; i < openDevices.size(); i++) {
			boolean e = false;
			for (String mid : openmids) {
				if (mid.equals(openDevices.get(i).getMainDeviceId())) {
					e = true;
				}
			}
			if (!e) {
				openmids.add(openDevices.get(i).getMainDeviceId());
			}
		}
		Log.i("wmy", "getMid = " + closeDevices.size());
		for (int i = 0; i < closeDevices.size(); i++) {
			boolean e = false;
			for (String mid : closemids) {
				if (mid.equals(closeDevices.get(i).getMainDeviceId())) {
					e = true;
				}
			}
			if (!e) {
				closemids.add(closeDevices.get(i).getMainDeviceId());
			}
		}
	}

	private void getDeviceMap() {
		// 遍历devices设备集合 获取每一个设备的主id
		// 将其放到以主id为key的设备集合中
		for (int i = 0; i < devices.size(); i++) {
			if (deviceMap.get(devices.get(i).getMainDeviceId()) == null) {
				deviceMap.put(devices.get(i).getMainDeviceId(), new ArrayList<Device>());
				deviceMap.get(devices.get(i).getMainDeviceId()).add(devices.get(i));
			} else {
				deviceMap.get(devices.get(i).getMainDeviceId()).add(devices.get(i));
			}
		}
	}

	private void getOpenCmd() {
		Log.e("wmy", "Scene getOpenCmd " + openmids.size());
		for (int i = 0; i < openmids.size(); i++) {
			if (openDevices.size() <= 10) {
				List<Device> ssDevices = new ArrayList<Device>();
				List<Device> curtainDevices = new ArrayList<Device>();
				List<Device> lDevices = new ArrayList<Device>();
				List<Device> linghuoDevices = new ArrayList<Device>();
				List<Device> linghuoDevices2 = new ArrayList<Device>();
				List<Device> linghuoDevices3 = new ArrayList<Device>();
				String name="";
				for (int n = 0; n < openDevices.size(); n++) {
					if (openDevices.get(n).getMainDeviceId().equals(openmids.get(i))) {
						switch (openDevices.get(n).getDeviceType()) {
							case DeviceType.DEVICE_TYPE_CURTAIN:
								curtainDevices.add(openDevices.get(n));
								break;
						case DeviceType.DEVICE_TYPE_SWITCH:
							case DeviceType.DEVICE_TYPE_CHAZUO:
						case DeviceType.DEVICE_TYPE_SOCKET:
							ssDevices.add(openDevices.get(n));
							break;
						case DeviceType.DEVICE_TYPE_RGB_LIGHT:
							lDevices.add(openDevices.get(n));
							break;
						case DeviceType.DEVICE_TYPE_AIR_CONTROLLER:
						case DeviceType.DEVICE_TYPE_BOX2:
						case DeviceType.DEVICE_TYPE_TV:
						case DeviceType.DEVICE_TYPE_PROJECTOR:
						case DeviceType.DEVICE_TYPE_FAN:
						case DeviceType.DEVICE_TYPE_DVD:
							break;
						case DeviceType.LINGHUO_SWITCH_1:
							linghuoDevices2.add(openDevices.get(n));
							break;
						case DeviceType.LINGHUO_SWITCH_2:
							name=openDevices.get(n).getSwitchName();
							if(name.contains("(1键)")){
								linghuoDevices.add(openDevices.get(n));
							}else if(name.contains("(2键)")){
								linghuoDevices3.add(openDevices.get(n));
							}
							break;
						case DeviceType.LINGHUO_SWITCH_3:
							name=openDevices.get(n).getSwitchName();;
							//int[] name1=openDevices.get(n).getDataOpenCmd();
							if(name.contains("(1键)")){
								linghuoDevices.add(openDevices.get(n));
							}else if(name.contains("(2键)")){
								linghuoDevices2.add(openDevices.get(n));
							}else if(name.contains("(3键)")){
								linghuoDevices3.add(openDevices.get(n));
							}
							break;
						default:
							break;
						}
					}
				}
				Cmd_Open cmd = new Cmd_Open();
				cmd.setMainDeviceId(openmids.get(i));
				cmd.setmSSDevices(ssDevices);
				cmd.setCurtainDevices(curtainDevices);
				cmd.setLingHuoDevices(linghuoDevices);
				cmd.setLingHuoDevices2(linghuoDevices2);
				cmd.setLingHuoDevices3(linghuoDevices3);
				cmd.setmLightDevices(lDevices);
				open_cmds.add(cmd);
				Log.e("wmy", sceneName + " open_cmds = " + open_cmds.size());
			} else {
				Log.i("wmy", "openDevices个数 = " + openDevices.size());
				for (int m = 0; m < (openDevices.size() / 10 + 1); m++) {
					Log.i("wmy", m + " " + (openDevices.size() / 10 + 1));
					if (m != openDevices.size() / 10) {
						List<Device> ssDevices = new ArrayList<Device>();
						List<Device> lDevices = new ArrayList<Device>();
						List<Device> curtainDevices = new ArrayList<Device>();
						List<Device> linghuoDevices = new ArrayList<Device>();
						List<Device> linghuoDevices2 = new ArrayList<Device>();
						List<Device> linghuoDevices3 = new ArrayList<Device>();
						String name="";
						for (int n = 0 + m * 10; n < 0 + (m + 1) * 10; n++) {
							if (openDevices.get(n).getMainDeviceId().equals(openmids.get(i))) {
								switch (openDevices.get(n).getDeviceType()) {
									case DeviceType.DEVICE_TYPE_CURTAIN:
										curtainDevices.add(openDevices.get(n));
										break;
								case DeviceType.DEVICE_TYPE_SWITCH:
									case DeviceType.DEVICE_TYPE_CHAZUO:
								case DeviceType.DEVICE_TYPE_SOCKET:
									ssDevices.add(openDevices.get(n));
									break;
								case DeviceType.DEVICE_TYPE_RGB_LIGHT:
									lDevices.add(openDevices.get(n));
									break;
									case DeviceType.LINGHUO_SWITCH_1:
										linghuoDevices2.add(openDevices.get(n));
										break;
									case DeviceType.LINGHUO_SWITCH_2:
										name=openDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(openDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices3.add(openDevices.get(n));
										}
										break;
									case DeviceType.LINGHUO_SWITCH_3:
										name=openDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(openDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices2.add(openDevices.get(n));
										}else if(name.contains("(3键)")){
											linghuoDevices3.add(openDevices.get(n));
										}
										break;
								default:
									break;
								}
							}
						}
						Cmd_Open cmd = new Cmd_Open();
						cmd.setMainDeviceId(openmids.get(i));
						cmd.setmSSDevices(ssDevices);
						cmd.setCurtainDevices(curtainDevices);
						cmd.setLingHuoDevices(linghuoDevices);
						cmd.setLingHuoDevices2(linghuoDevices2);
						cmd.setLingHuoDevices3(linghuoDevices3);
						cmd.setmLightDevices(lDevices);
						open_cmds.add(cmd);
						Log.e("wmy", "添加一个指令cmd = " + cmd.getOpenCmdl());
					} else {
						List<Device> ssDevices = new ArrayList<Device>();
						List<Device> lDevices = new ArrayList<Device>();
						List<Device> curtainDevices = new ArrayList<Device>();
						List<Device> linghuoDevices = new ArrayList<Device>();
						List<Device> linghuoDevices2 = new ArrayList<Device>();
						List<Device> linghuoDevices3 = new ArrayList<Device>();
						String name="";
						Log.e("wmy", "0 + m * 10 = " + (0 + m * 10) + " openDevices.size() = " + openDevices.size());
						for (int n = 0 + m * 10; n < openDevices.size(); n++) {
							if (openDevices.get(n).getMainDeviceId().equals(openmids.get(i))) {
								switch (openDevices.get(n).getDeviceType()) {
									case DeviceType.DEVICE_TYPE_CURTAIN:
										curtainDevices.add(openDevices.get(n));
										break;
								case DeviceType.DEVICE_TYPE_SWITCH:
									case DeviceType.DEVICE_TYPE_CHAZUO:
								case DeviceType.DEVICE_TYPE_SOCKET:
									ssDevices.add(openDevices.get(n));
									break;
								case DeviceType.DEVICE_TYPE_RGB_LIGHT:
									lDevices.add(openDevices.get(n));
									break;
									case DeviceType.LINGHUO_SWITCH_1:
										linghuoDevices2.add(openDevices.get(n));
										break;
									case DeviceType.LINGHUO_SWITCH_2:
										name=openDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(openDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices3.add(openDevices.get(n));
										}
										break;
									case DeviceType.LINGHUO_SWITCH_3:
										name=openDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(openDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices2.add(openDevices.get(n));
										}else if(name.contains("(3键)")){
											linghuoDevices3.add(openDevices.get(n));
										}
										break;
								default:
									break;
								}
							}
						}
						// Log.e("wmy", sceneName + " " + m + " 添加一个集合
						// lDevices.size() = " + lDevices.size());
						Cmd_Open cmd = new Cmd_Open();
						cmd.setMainDeviceId(openmids.get(i));
						cmd.setCurtainDevices(curtainDevices);
						cmd.setLingHuoDevices(linghuoDevices);
						cmd.setLingHuoDevices2(linghuoDevices2);
						cmd.setLingHuoDevices3(linghuoDevices3);
						cmd.setmSSDevices(ssDevices);
						cmd.setmLightDevices(lDevices);
						open_cmds.add(cmd);
						Log.e("wmy", "添加一个指令cmd = " + cmd.getOpenCmdl());
					}
				}
			}
		}
	}

	private void getCloseCmd() {
		Log.e("wmy", "Scene getCloseCmd " + closemids.size());
		for (int i = 0; i < closemids.size(); i++) {
			// Cmd_Close cmd = new Cmd_Close();
			// cmd.setMainDeviceId(closemids.get(i));
			// List<Device> ssDevices = new ArrayList<Device>();
			// List<Device> lDevices = new ArrayList<Device>();
			Log.e("wmy", "closeDevices = " + closeDevices.size() + " closemids = " + closemids.size());
			if (closeDevices.size() <= 10) {
				List<Device> ssDevices = new ArrayList<Device>();
				List<Device> lDevices = new ArrayList<Device>();
				List<Device> curtainDevices = new ArrayList<Device>();
				List<Device> linghuoDevices = new ArrayList<Device>();
				List<Device> linghuoDevices2 = new ArrayList<Device>();
				List<Device> linghuoDevices3 = new ArrayList<Device>();
				String name="";
				for (int n = 0; n < closeDevices.size(); n++) {
					if (closeDevices.get(n).getMainDeviceId().equals(closemids.get(i))) {
						switch (closeDevices.get(n).getDeviceType()) {
							case DeviceType.DEVICE_TYPE_CURTAIN:
								curtainDevices.add(closeDevices.get(n));
								break;
						case DeviceType.DEVICE_TYPE_SWITCH:
							case DeviceType.DEVICE_TYPE_CHAZUO:
						case DeviceType.DEVICE_TYPE_SOCKET:
							ssDevices.add(closeDevices.get(n));
							break;
						case DeviceType.DEVICE_TYPE_RGB_LIGHT:
							lDevices.add(closeDevices.get(n));
							break;
						case DeviceType.DEVICE_TYPE_AIR_CONTROLLER:
						case DeviceType.DEVICE_TYPE_BOX2:
						case DeviceType.DEVICE_TYPE_TV:
						case DeviceType.DEVICE_TYPE_PROJECTOR:
						case DeviceType.DEVICE_TYPE_FAN:
						case DeviceType.DEVICE_TYPE_DVD:
							break;
							case DeviceType.LINGHUO_SWITCH_1:
								linghuoDevices2.add(closeDevices.get(n));
								break;
							case DeviceType.LINGHUO_SWITCH_2:
								name=closeDevices.get(n).getSwitchName();
								if(name.contains("(1键)")){
									linghuoDevices.add(closeDevices.get(n));
								}else if(name.contains("(2键)")){
									linghuoDevices3.add(closeDevices.get(n));
								}
								break;
							case DeviceType.LINGHUO_SWITCH_3:
								name=closeDevices.get(n).getSwitchName();
								if(name.contains("(1键)")){
									linghuoDevices.add(closeDevices.get(n));
								}else if(name.contains("(2键)")){
									linghuoDevices2.add(closeDevices.get(n));
								}else if(name.contains("(3键)")){
									linghuoDevices3.add(closeDevices.get(n));
								}
								break;
						default:
							break;
						}
					}
				}
				Cmd_Close cmd = new Cmd_Close();
				cmd.setMainDeviceId(closemids.get(i));
				cmd.setmSSDevices(ssDevices);
				cmd.setCurtainDevices(curtainDevices);
				cmd.setLingHuoDevices(linghuoDevices);
				cmd.setLingHuoDevices2(linghuoDevices2);
				cmd.setLingHuoDevices3(linghuoDevices3);
				cmd.setmLightDevices(lDevices);
				close_cmds.add(cmd);
			} else {
				Log.i("wmy", "closeDevices个数 = " + closeDevices.size());
				for (int m = 0; m < (closeDevices.size() / 10 + 1); m++) {
					Log.i("wmy", m + " " + (closeDevices.size() / 10 + 1));
					if (m != closeDevices.size() / 10) {
						List<Device> ssDevices = new ArrayList<Device>();
						List<Device> lDevices = new ArrayList<Device>();
						List<Device> curtainDevices = new ArrayList<Device>();
						List<Device> linghuoDevices = new ArrayList<Device>();
						List<Device> linghuoDevices2 = new ArrayList<Device>();
						List<Device> linghuoDevices3 = new ArrayList<Device>();
						String name="";
						for (int n = 0 + m * 10; n < 0 + (m + 1) * 10; n++) {
							if (closeDevices.get(n).getMainDeviceId().equals(closemids.get(i))) {
								switch (closeDevices.get(n).getDeviceType()) {
									case DeviceType.DEVICE_TYPE_CURTAIN:
										curtainDevices.add(closeDevices.get(n));
										break;
								case DeviceType.DEVICE_TYPE_SWITCH:
									case DeviceType.DEVICE_TYPE_CHAZUO:
								case DeviceType.DEVICE_TYPE_SOCKET:
									ssDevices.add(closeDevices.get(n));
									break;
								case DeviceType.DEVICE_TYPE_RGB_LIGHT:
									lDevices.add(closeDevices.get(n));
									break;
									case DeviceType.LINGHUO_SWITCH_1:
										linghuoDevices2.add(closeDevices.get(n));
										break;
									case DeviceType.LINGHUO_SWITCH_2:
										name=closeDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(closeDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices3.add(closeDevices.get(n));
										}
										break;
									case DeviceType.LINGHUO_SWITCH_3:
										name=closeDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(closeDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices2.add(closeDevices.get(n));
										}else if(name.contains("(3键)")){
											linghuoDevices3.add(closeDevices.get(n));
										}
										break;
									default:
									break;
								}
							}
						}
						Cmd_Close cmd = new Cmd_Close();
						cmd.setMainDeviceId(closemids.get(i));
						cmd.setmSSDevices(ssDevices);
						cmd.setCurtainDevices(curtainDevices);
						cmd.setLingHuoDevices(linghuoDevices);
						cmd.setLingHuoDevices2(linghuoDevices2);
						cmd.setLingHuoDevices3(linghuoDevices3);
						cmd.setmLightDevices(lDevices);
						close_cmds.add(cmd);
						Log.e("wmy", "添加一个指令cmd = " + cmd.getCloseCmdl());
					} else {
						List<Device> ssDevices = new ArrayList<Device>();
						List<Device> lDevices = new ArrayList<Device>();
						List<Device> curtainDevices = new ArrayList<Device>();
						List<Device> linghuoDevices = new ArrayList<Device>();
						List<Device> linghuoDevices2 = new ArrayList<Device>();
						List<Device> linghuoDevices3 = new ArrayList<Device>();
						String name="";
						Log.e("wmy", "0 + m * 10 = " + (0 + m * 10) + " closeDevices.size() = " + closeDevices.size());
						for (int n = 0 + m * 10; n < closeDevices.size(); n++) {
							if (closeDevices.get(n).getMainDeviceId().equals(closemids.get(i))) {
								switch (closeDevices.get(n).getDeviceType()) {
									case DeviceType.DEVICE_TYPE_CURTAIN:
										curtainDevices.add(closeDevices.get(n));
										break;
								case DeviceType.DEVICE_TYPE_SWITCH:
									case DeviceType.DEVICE_TYPE_CHAZUO:
								case DeviceType.DEVICE_TYPE_SOCKET:
									ssDevices.add(closeDevices.get(n));
									break;
								case DeviceType.DEVICE_TYPE_RGB_LIGHT:
									lDevices.add(closeDevices.get(n));
									break;
									case DeviceType.LINGHUO_SWITCH_1:
										linghuoDevices2.add(closeDevices.get(n));
										break;
									case DeviceType.LINGHUO_SWITCH_2:
										name=closeDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(closeDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices3.add(closeDevices.get(n));
										}
										break;
									case DeviceType.LINGHUO_SWITCH_3:
										name=closeDevices.get(n).getSwitchName();
										if(name.contains("(1键)")){
											linghuoDevices.add(closeDevices.get(n));
										}else if(name.contains("(2键)")){
											linghuoDevices2.add(closeDevices.get(n));
										}else if(name.contains("(3键)")){
											linghuoDevices3.add(closeDevices.get(n));
										}
										break;
									default:
									break;
								}
							}
						}
						// Log.e("wmy", sceneName + " " + m + " 添加一个集合
						// lDevices.size() = " + lDevices.size());
						Cmd_Close cmd = new Cmd_Close();
						cmd.setMainDeviceId(closemids.get(i));
						cmd.setmSSDevices(ssDevices);
						cmd.setCurtainDevices(curtainDevices);
						cmd.setLingHuoDevices(linghuoDevices);
						cmd.setLingHuoDevices2(linghuoDevices2);
						cmd.setLingHuoDevices3(linghuoDevices3);
						cmd.setmLightDevices(lDevices);
						close_cmds.add(cmd);
						Log.e("wmy", "添加一个指令cmd = " + cmd.getCloseCmdl());
					}
				}
			}
			Log.e("wmy", "393 close_cmds = " + close_cmds.size());
		}
	}

	private void getIrCmd() {
		Log.i("wmy", "413 getIrCmd closeDevices = " + closeDevices.size());
		for (int i = 0; i < closeDevices.size(); i++) {
			switch (closeDevices.get(i).getDeviceType()) {
			case DeviceType.DEVICE_TYPE_AIR_CONTROLLER:
			case DeviceType.DEVICE_TYPE_BOX2:
			case DeviceType.DEVICE_TYPE_TV:
			case DeviceType.DEVICE_TYPE_PROJECTOR:
			case DeviceType.DEVICE_TYPE_FAN:
			case DeviceType.DEVICE_TYPE_DVD:
				close_ir_devices.add(closeDevices.get(i));
				break;

			default:
				break;
			}
		}
		for (int i = 0; i < openDevices.size(); i++) {
			switch (openDevices.get(i).getDeviceType()) {
			case DeviceType.DEVICE_TYPE_AIR_CONTROLLER:
			case DeviceType.DEVICE_TYPE_BOX2:
			case DeviceType.DEVICE_TYPE_TV:
			case DeviceType.DEVICE_TYPE_PROJECTOR:
			case DeviceType.DEVICE_TYPE_FAN:
			case DeviceType.DEVICE_TYPE_DVD:
				open_ir_devices.add(openDevices.get(i));
				break;

			default:
				break;
			}
		}
		Log.i("wmy", "closemids = " + closemids + " close_ir_devices = " + close_ir_devices.size());
		for (int i = 0; i < closemids.size(); i++) {
			for (int n = 0; n < close_ir_devices.size(); n++) {
				if (close_ir_devices.get(n).getMainDeviceId().equals(closemids.get(i))) {
					Cmd_Close close_cmd = new Cmd_Close();
					close_cmd.setMainDeviceId(closemids.get(i));
					String cmd = "";
					boolean add = false;
					for (int m = 0; m < close_ir_devices.get(n).getKeys().size(); m++) {

						if (close_ir_devices.get(n).getKeys().get(m).getKeyNum() == 4000) {
							try {
								cmd = close_ir_devices.get(n).getKeys().get(m).getCodeValue();
								Log.i("wmy", "获取遥控器指令 关" + close_ir_devices.get(n).getSwitchName() + " " + cmd);
								cmd = ConvertUtil.getInstance().convertInfraredCmd(cmd);
								close_cmd.setIr_deviceId(close_ir_devices.get(n).getDeviceID());
								close_cmd.setIr_cmd(cmd);
								close_cmds.add(close_cmd);
								add = true;
							} catch (Exception e) {
								// TODO: handle exception
							}
						}
					}
					if (!add) {
						for (int m = 0; m < close_ir_devices.get(n).getKeys().size(); m++) {

							if (close_ir_devices.get(n).getKeys().get(m).getKeyNum() == 800) {
								try {
									cmd = close_ir_devices.get(n).getKeys().get(m).getCodeValue();
									Log.i("wmy", "获取遥控器指令 关" + close_ir_devices.get(n).getSwitchName() + " " + cmd);
									cmd = ConvertUtil.getInstance().convertInfraredCmd(cmd);
									close_cmd.setIr_deviceId(close_ir_devices.get(n).getDeviceID());
									close_cmd.setIr_cmd(cmd);
									close_cmds.add(close_cmd);
									add = true;
								} catch (Exception e) {
									// TODO: handle exception
								}
							}
						}
					}
				}
			}
		}
		for (int i = 0; i < openmids.size(); i++) {
			for (int n = 0; n < open_ir_devices.size(); n++) {
				if (open_ir_devices.get(n).getMainDeviceId().equals(openmids.get(i))) {
					Cmd_Open open_cmd = new Cmd_Open();
					open_cmd.setMainDeviceId(openmids.get(i));
					for (int m = 0; m < open_ir_devices.get(n).getKeys().size(); m++) {
						if (open_ir_devices.get(n).getKeys().get(m).getKeyNum() == 800) {
							Log.i("wmy", "进入 " + open_ir_devices.get(n).getKeys().get(m).getCodeValue());
							try {
								String cmd = open_ir_devices.get(n).getKeys().get(m).getCodeValue();
								cmd = ConvertUtil.getInstance().convertInfraredCmd(cmd);
								Log.i("wmy", "cmd = " + cmd);
								open_cmd.setIr_deviceId(open_ir_devices.get(n).getDeviceID());
								open_cmd.setIr_cmd(cmd);
								open_cmds.add(open_cmd);
								Log.i("wmy", "添加了一个开的指令 " + cmd);
							} catch (Exception e) {
								// TODO: handle exception
								Log.e("wmy", "e.toString() = " + e.toString());
							}
						}
					}

				}
			}
		}
	}

	public List<Cmd_Open> getOpenCmds() {
		return open_cmds;
	}

	public List<Cmd_Close> getCloseCmds() {
		return close_cmds;
	}

	public void setDeviceMap(HashMap<String, List<Device>> deviceMap) {
		this.deviceMap = deviceMap;
	}

}
